package Stack;

import java.util.Arrays;

public class MyStack {

    public int[] elem;
    public int useSize;

    public MyStack(){
        this.elem = new int[10];
    }

    public void push(int val){
        if (isFull()){
            this.elem= Arrays.copyOf(elem,2*elem.length);
        }
        elem[useSize++] = val;
    }

    public boolean isFull(){
        return useSize == elem.length;
    }

    public int pop(){
        if (isEmpty()){
            throw new EmptyStackException();
        }
        int val = elem[useSize-1];
        useSize--;
        return val;
    }

    public boolean isEmpty(){
        return useSize == 0;
    }

    public int peek(){
        if (isEmpty()){
            throw new EmptyStackException();
        }
        return elem[useSize-1];
    }


}
